﻿/*
 * Rappelz: Endless Odyssey - The first free open source Rappelz server emulator
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rappelz.GameServer.Network;
using System.Data.Common;
using System.Data;
using Rappelz.GameServer.Network.GameClient;

namespace Rappelz.GameServer.Database
{
    /// <summary>
    /// DB_InsertSummon (smp_insert_favor)
    /// </summary>
    public class DB_InsertSummon : IDBProc
    {
        private Player m_pMaster;
        private int sid;
        private int account_id;
        private int owner_id;
        private int code;
        private long card_uid;
        private string strName;
        private int sp;
        private int hp;
        private int mp;

        public BaseObject m_CBObject = null;

        public DB_InsertSummon(Player pMaster, int _sid, int _account_id, int _owner_id, int _code, long _card_uid, string szName, int _sp, int _hp, float _mp)
        {
            this.m_pMaster = pMaster;
            this.sid = _sid;
            this.account_id = _account_id;
            this.owner_id = _owner_id;
            this.code = _code;
            this.card_uid = _card_uid;
            this.strName = szName;
            this.sp = _sp;
            this.hp = _hp;
            this.mp = (int)_mp;
        }

        public void SetCB(BaseObject obj)
        {
            m_CBObject = obj;
        }

        public void RunCB()
        {
            if (m_CBObject != null)
                m_CBObject.onEndQuery();
        }

        public bool onProcess()
        {
            DbConnection conn = GameDBManager.Instance.CreateConnection();
            DbCommand cmd = conn.CreateCommand();

            cmd.CommandText = "smp_insert_summon";
            cmd.CommandType = CommandType.StoredProcedure;

            DbParameter IN_SID = GameDBManager.Instance.CreateInParameter(cmd, "IN_SID", DbType.Int32, this.sid);
            DbParameter IN_ACCOUNT_ID = GameDBManager.Instance.CreateInParameter(cmd, "IN_ACCOUNT_ID", DbType.Int32, this.account_id);
            DbParameter IN_OWNER_ID = GameDBManager.Instance.CreateInParameter(cmd, "IN_OWNER_ID", DbType.Int32, this.owner_id);
            DbParameter IN_CODE = GameDBManager.Instance.CreateInParameter(cmd, "IN_CODE", DbType.Int32, this.code);
            DbParameter IN_CARD_UID = GameDBManager.Instance.CreateInParameter(cmd, "IN_CARD_UID", DbType.Int32, this.card_uid);
            DbParameter IN_NAME = GameDBManager.Instance.CreateInParameter(cmd, "IN_NAME", DbType.String, this.strName);
            DbParameter IN_SP = GameDBManager.Instance.CreateInParameter(cmd, "IN_SP", DbType.Int32, this.sp);
            DbParameter IN_HP = GameDBManager.Instance.CreateInParameter(cmd, "IN_HP", DbType.Int32, this.hp);
            DbParameter IN_MP = GameDBManager.Instance.CreateInParameter(cmd, "IN_MP", DbType.Int32, this.mp);

            conn.Open();
            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Globals.Log.Error("DB_InsertSummon.onProcess Exception: {0}", ex);
            }
            conn.Close();

            return true;
        }
    }


}
